Page({
  data: {
    statusBarHeight: 0, //胶囊按钮高度
    tmplIds1: '',
    tmplIds2: '',
  },
  onLoad: function (options) {
    wx.hideShareMenu()
    let slet = this;
    console.log('TOP2:', getApp().globalData.statusBarHeight);
    slet.setData({
      statusBarHeight: getApp().globalData.statusBarHeight
    })

    wx.request({
      url: getApp().data.apiUrl + '/GetWxTemplate.ashx',
      data: {
        idlist: '2,6'
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        var resdata = JSON.parse(decodeURIComponent(JSON.stringify(res.data)));
        console.log(resdata);
        slet.setData({
          tmplIds1: resdata.tmplIds
        })
      }
    })

    wx.request({
      url: getApp().data.apiUrl + '/GetWxTemplate.ashx',
      data: {
        idlist: '3,4,6'
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        var resdata = JSON.parse(decodeURIComponent(JSON.stringify(res.data)));
        console.log(resdata);
        slet.setData({
          tmplIds2: resdata.tmplIds
        })
      }
    })
  },
  onShow: function () {

  },
  toHome(e) //回首页
  {
    wx.redirectTo({
      url: '/pages/index',
    })
  },
  toBlack(e) //返回
  {
    wx.redirectTo({
      url: '/pages/index',
    })
    // wx.navigateBack({
    //   delta: 1
    // })
  },
  onSubscribe1(e) {
    let slet = this;
    let tmplIds1 = slet.data.tmplIds1;
    if (tmplIds1.length < 10) {
      wx.navigateTo({
        url: 'adddog',
      })
      return;
    }
    let tmplIds = '[' + tmplIds1 + ']' //订阅消息ID
    tmplIds = tmplIds.replace(/@/g, '"');
    tmplIds = JSON.parse(tmplIds);
    console.log(tmplIds);
    // 调用微信 API 申请发送订阅消息
    wx.requestSubscribeMessage({
      // 传入订阅消息的模板id，模板 id 可在小程序管理后台申请
      tmplIds: tmplIds,
      success(res) {
        console.log(res);
        //申请订阅成功
        if (res.errMsg === 'requestSubscribeMessage:ok') {

        }
        wx.navigateTo({
          url: 'adddog',
        })
      }
    });
  },
  onSubscribe2(e) {
    let slet = this;
    let tmplIds2 = slet.data.tmplIds2;
    if (tmplIds2.length < 10) {
      wx.navigateTo({
        url: 'addmaster',
      })
      return;
    }
    let tmplIds = '[' + tmplIds2 + ']' //订阅消息ID
    tmplIds = tmplIds.replace(/@/g, '"');
    tmplIds = JSON.parse(tmplIds);
    console.log(tmplIds);
    // 调用微信 API 申请发送订阅消息
    wx.requestSubscribeMessage({
      // 传入订阅消息的模板id，模板 id 可在小程序管理后台申请
      tmplIds: tmplIds,
      success(res) {
        console.log(res);
        //申请订阅成功
        if (res.errMsg === 'requestSubscribeMessage:ok') {

        }
        wx.navigateTo({
          url: 'addmaster',
        })
      }
    });
  },
  toXgqs(e) //发布寻狗启事
  {
    wx.navigateTo({
      url: 'adddog',
    })
  },
  toXzqs(e) //发布寻主启事
  {
    wx.navigateTo({
      url: 'addmaster',
      //url: '../xq/release',
    })
  }
})